﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace MyFinanceManager.Objects
{
    public class Filenames
    {
        private const string fnDatabase = "Datenbank.xml";
        private const string fnAccounts = "Konten.txt";
        private const string fnCatIn = "CategoryIn.txt";
        private const string fnCatEx = "CategoryEx.txt";
        private const string fnFolder = "My Finance Manager";
        private const string fnLastM = "LastMileometer.txt";

        private static string filenameDatabase = string.Empty;
        public static string FilenameDatabase
        {
            get
            {
                if (String.IsNullOrEmpty(filenameDatabase))
                {
                    filenameDatabase = CreateFile(fnDatabase);
                }
                return filenameDatabase;
            }
        }

        private static string filenameAccounts = string.Empty;
        public static string FilenameAccounts
        {
            get
            {
                if (String.IsNullOrEmpty(filenameAccounts))
                {
                    filenameAccounts = CreateFile(fnAccounts);
                }
                return filenameAccounts;
            }
        }

        private static string filenameCategoryIn = string.Empty;
        public static string FilenameCategoryIn
        {
            get
            {
                if (String.IsNullOrEmpty(filenameCategoryIn))
                {
                    filenameCategoryIn = CreateFile(fnCatIn);
                }
                return filenameCategoryIn;
            }
        }

        private static string filenameCategoryEx = string.Empty;
        public static string FilenameCategoryEx
        {
            get
            {
                if (String.IsNullOrEmpty(filenameCategoryEx))
                {
                    filenameCategoryEx = CreateFile(fnCatEx);
                }
                return filenameCategoryEx;
            }
        }

        private static string filenameLastMileometer = string.Empty;
        public static string FilenameLastMileometer
        {
            get
            {
                if (String.IsNullOrEmpty(filenameLastMileometer))
                {
                    filenameLastMileometer = CreateFile(fnLastM);
                }
                return filenameLastMileometer;
            }
        }

        private static string folderMyFinanceManager = string.Empty;
        public static string FolderMyFinanceManager
        {
            get
            {
                if (string.IsNullOrEmpty(folderMyFinanceManager))
                {
                    string personal = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
                    folderMyFinanceManager = Path.Combine(personal, fnFolder);
                    if (!Directory.Exists(folderMyFinanceManager))
                        Directory.CreateDirectory(folderMyFinanceManager);
                }
                return folderMyFinanceManager;
            }
        }

        private Filenames() { }

        private static string CreateFile(string filenameConst)
        {
            string filename = Path.Combine(FolderMyFinanceManager, filenameConst);
            if (!File.Exists(filename))
                File.Create(filename).Dispose();
            return filename;
        }
    }
}
